﻿/// <reference path="jquery-1.8.2.min.js" />
/// <reference path="menu.js" />
/// <reference path="templating.js" />
/// <reference path="data.js" />
/// <reference path="portfolio.js" />


var site = {
    // Framework items
    animationManager: null,
    templating: null,
    data: null,
    
    // Pages items
    menu: null,
    portfolio: null,
    experiments: null,
    cv: null,
    

};

$(document).ready(function () {

    var trySendReady = function() {
        if(site.templating.loaded && site.data.loaded) {
            if (site.menu && site.menu.OnReady) { site.menu.OnReady(); }
            if (site.portfolio && site.portfolio.OnReady) { site.portfolio.OnReady(); }
            if (site.experiments && site.experiments.OnReady) { site.experiments.OnReady(); }
            if (site.cv && site.cv.OnReady) { site.cv.OnReady(); }
        }
    };

    site.templating.onload = function () {
        if (site.menu && site.menu.OnTemplateLoaded) { site.menu.OnTemplateLoaded(); }
        if (site.portfolio && site.portfolio.OnTemplateLoaded) { site.portfolio.OnTemplateLoaded(); }
        if (site.experiments && site.experiments.OnTemplateLoaded) { site.experiments.OnTemplateLoaded(); }
        if (site.cv && site.cv.OnTemplateLoaded) { site.cv.OnTemplateLoaded(); }
        trySendReady();
    };
    
    site.data.onload = function () {
        if (site.menu && site.menu.OnDataLoaded) { site.menu.OnDataLoaded(); }
        if (site.portfolio && site.portfolio.OnDataLoaded) { site.portfolio.OnDataLoaded(); }
        if (site.experiments && site.experiments.OnDataLoaded) { site.experiments.OnDataLoaded(); }
        if (site.cv && site.cv.OnDataLoaded) { site.cv.OnDataLoaded(); }
        trySendReady();
    };

    if (site.menu && site.menu.InitializeComponent) { site.menu.InitializeComponent(); }
    if (site.portfolio && site.portfolio.InitializeComponent) { site.portfolio.InitializeComponent(); }
    if (site.experiments && site.experiments.InitializeComponent) { site.experiments.InitializeComponent(); }
    if (site.cv && site.cv.InitializeComponent) { site.cv.InitializeComponent(); }

    for (var template in site.templating.templates) {
        site.templating.templates[template].Build();
    }
    
    for (var item in site.data.items) {
        site.data.items[item].Build();
    }
});